package com.sky.controller.user;


import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVo;
import com.sky.vo.OrderVo;
import com.sky.websocket.WebSocketServer;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @Autowired
    private WebSocketServer webSocket;

    @PostMapping("/submit")
    public Result<OrderSubmitVo> submit(@RequestBody  OrdersSubmitDTO ordersSubmitDTO){
      log.info("用户下单：{}",ordersSubmitDTO);
       OrderSubmitVo orderSubmitVo=orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVo);

    }

    @ApiOperation("历史订单查询")
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrdrers(Integer pageSize,Integer page,Integer status)
    {
        log.info("历史订单查询");
        PageResult pageResult = orderService.historyOrdrers(pageSize, page, status);
        return Result.success(pageResult);
    }

    @ApiOperation("查看订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVo> getOrderDetail(@PathVariable Long id)
    {
        log.info("查看订单详情");
        OrderVo orderVo = orderService.getOrderDetail(id);
        return Result.success(orderVo);
    }

    @ApiOperation("取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancel(@PathVariable Long id)
    {
        log.info("取消订单");
        orderService.cancel(id);
        return Result.success();
    }

    @ApiOperation("再来一单")
   @PostMapping("/repetition/{id}")
    public  Result repetition(@PathVariable Long id)
    {
        log.info("再来一单");
        orderService.repetition(id);
        return Result.success();
    }

    @ApiOperation("客户催单")
 @GetMapping("/reminder/{id}")
public Result reminder(@PathVariable("id") Long id)
{
    log.info("客户催单");
    orderService.reminder(id);
    return Result.success();
}
}
